#ifndef CITLSSPPROCPROXY_H_
#define CITLSSPPROCPROXY_H_

#include <iostream>
#include <mutex>
#include <thread>
#include "IValidatorInterface.h"

// \brief ITL 纸币器接口
class CITLValidatorImpl : public zl::IValidatorInterface
{
public:
    CITLValidatorImpl();
    ~CITLValidatorImpl();

    int32_t Initialize(const std::string& com, int32_t baud, zl::IValidatorObserver* obs) override;
    int32_t Uninitialize() override;
    int32_t Status() override;
    int32_t Reset() override;
    int32_t Setup() override;
    int32_t Enable() override;
    int32_t Disable() override;

protected:
    // SSP COMMANDS
    int32_t ssp_cmd_enable();
    int32_t ssp_cmd_disable();
    int32_t ssp_cmd_return_note();
    int32_t ssp_cmd_reset();
    int32_t ssp_cmd_sync();
    int32_t ssp_cmd_setup_request();
    int32_t ssp_cmd_set_inhibits();
    int32_t ssp_cmd_poll();
    int32_t ssp_cmd_set_version();

    int get_channel_value(int channel_num);
    std::string get_channel_currency(int channel_num);
    bool check_generic_responses();
    bool ssp_send_command();
    static void poll_loop_worker(CITLValidatorImpl* ptr);

private:
    struct SSPImpl;
    SSPImpl* impl_;
    std::mutex mutex_;
    std::mutex mutex_api_;
    zl::IValidatorObserver* obs_;
    bool polling_flag_;
    bool polling_thread_flag_;
    std::thread* polling_thread_;
    bool init_flag_;

    int32_t status_;
};

#endif // CITLSSPPROCPROXY_H_
